/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package MathLib.Geometry;

import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;

/**
 *
 * @author marko
 */
public class GPolygon implements IFigure{
    public String Name="";
    protected int N;
    protected double R;
    protected ArrayList<Point2DDouble> ListOfApexes;
    protected Point2DDouble Center;

    public GPolygon(int n,Point2DDouble center, double R){
        Center = center;
        N = n;
        this.R = R;//Math.cos(2*Math.PI/N)
        ListOfApexes = new ArrayList<Point2DDouble>(N);
        double x0 = Center.x,y0 = Center.y + R;
        for(int i =0;i<N;i++){
            ListOfApexes.add(new Point2DDouble(Math.cos(2*Math.PI/N*i)*x0 + Math.sin(2*Math.PI/N*i)*y0, -Math.sin(2*Math.PI/N*i)*x0 + Math.cos(2*Math.PI/N*i)*y0));
        }
    }

    public Point2DDouble Get(int i){
        try{
            return new Point2DDouble(ListOfApexes.get(i));
        }catch(Exception e){
            return null;
        }
    }

    public double GetX(int i){
        return ListOfApexes.get(i).x;
    }

    public double GetY(int i){
        return ListOfApexes.get(i).y;
    }

    public boolean Include(Point2DDouble x) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void printToFile(BufferedOutputStream out) {
        PrintWriter o = new PrintWriter(out);
        o.println(ListOfApexes.size()+" 2 0 0");
        int n = ListOfApexes.size();
        for(int i=0;i<n;i++){
            Point2DDouble point = ListOfApexes.get(i);
            o.println((i+1)+" "+point.x+" "+point.y);
        }
        o.println(ListOfApexes.size()+" 0");
        for(int i=1;i<n;i++){
            o.println(i+" "+ i + " " + (i+1));
        }
        o.println(n+" "+ n + " " + 1);
        o.println("0");
        o.close();
    }

    public void printToFileQuad(BufferedOutputStream out) {
        PrintWriter o = new PrintWriter(out);
        o.println(ListOfApexes.size());
        int n = ListOfApexes.size();
        for(int i=0;i<n;i++){
            Point2DDouble point = ListOfApexes.get(i);
            o.println(point.x+" "+point.y+" 2");
        }
        o.println("0\n1");
        o.println(ListOfApexes.size()+" 0 0");
        for(int i=1;i<=n;i++){
            o.print(i+" ");
        }
        o.println();
        for(int i=1;i<=n;i++){
            o.print("2 ");
        }
        o.close();
    }
}
